<template>
  <div>
    <el-form ref="form" :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="手机号">
        <el-input v-model="formInline.keywords" placeholder="请输入……" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch('form')">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID"  width="100"></el-table-column>
      <el-table-column prop="mobile" label="手机号"  width="160"></el-table-column>
      <el-table-column prop="text" label="内容"></el-table-column>
      <el-table-column prop="create_time" label="时间"  width="150"></el-table-column>
      <el-table-column prop="status_text" label="状态" width="130"></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @current-change="handleCurrentChange"
        layout="total, prev, pager, next"
        :page-size="pageData.per_page"
        :total="pageData.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {mapState} from 'vuex'

  export default {
    data () {
      return {
        formInline: {
          keywords: ''
        }
      }
    },
    computed: {
      ...mapState({
        tableData: state => state.sms.logList,
        pageData: state => state.sms.pageData
      })
    },
    created () {
      this.logList()
    },
    methods: {
      // 获取短信日志列表
      logList () {
        let payload = {
          page: this.pageData.current_page,
          listRows: this.pageData.per_page,
          keywords: this.$route.query.keywords
        }
        this.$store.dispatch('sms/logList', payload)
      },
      // 处理检索条件
      onSearch (formName) {
        const self = this
        self.$refs[formName].validate((valid) => {
          if (valid) {
            self.$router.push({path: '/sms/loglist', query: {keywords: self.formInline.keywords}})
            self.logList()
          }
        })
      },
      // 点击翻页时操作
      handleCurrentChange (val) {
        this.pageData.current_page = val
        this.logList()
      }
    }
  }
</script>
